home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / XLisp-Stat / Book / randu.lsp < prev    next >
Lisp/Scheme  |  1990-10-11  |  389b  |  14 lines

  1. ; book p.41
  2.  
  3. (defun randu (n &optional (seed 12345))
  4.   (let ((a (+ (^ 2 16) 3))
  5.         (m (^ 2 31)))
  6.     (flet ((mod (x m) (- x (* m (floor (/ x m))))))
  7.       (do ((i 0 (+ i 1))
  8.            (res (list seed)
  9.                 (cons (mod (* a (first res)) m) res)))
  10.           ((>= i n)
  11.            (/ (rest (reverse res)) m))))))
  12.  
  13. (def randu (apply #'mapcar #'list (split-list (randu 300) 3)))
  14.